package com.auto.api.mapping.controller;

import com.auto.api.core.entity.ApiInfo;
import com.auto.api.common.entity.ListData;
import com.auto.api.common.entity.ResultData;
import com.auto.api.common.utils.BeanMapper;
import com.auto.api.mapping.component.ApiInfoManager;
import com.auto.api.mapping.controller.vo.RequestToMethodItemVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program:
 * @description: API
 * @author: liangshf
 * @create: 2021-01-27
 */
@RestController
@RequestMapping("/mapping/api")
public class ApiInfoController {

    @Autowired(required = false)
    private ApiInfoManager apiItemMapping;

    @ApiOperation(value = "API-列表")
    @PostMapping(value = "/list")
    public ResultData<ListData<RequestToMethodItemVO>> list(@RequestBody @Validated RequestToMethodItemVO paramVO) {
        if (apiItemMapping == null) {
            ResultData.ok();
        }
        return ResultData.ok(ListData.newList(BeanMapper.mapList(apiItemMapping.findList(BeanMapper.map(paramVO, ApiInfo.class)), RequestToMethodItemVO.class)));
    }
}